package com.oceansoft.mobile.econsole.modules.api.v2.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oceansoft.mobile.econsole.common.util.encrypt.DesAPPUtils;
import com.oceansoft.mobile.econsole.common.util.web.PageUtil;
import com.oceansoft.mobile.econsole.modules.api.v2.service.IProjectYyService;
import com.oceansoft.mobile.econsole.modules.ascproject.entity.*;
import com.oceansoft.mobile.econsole.modules.ascproject.persistence.IProjectYyMapper;
import com.oceansoft.mobile.econsole.modules.base.entity.Pager;
import com.oceansoft.mobile.econsole.modules.base.entity.Query;
import com.oceansoft.mobile.econsole.modules.base.entity.Result;
import com.oceansoft.mobile.econsole.modules.jlwt.entity.IstPascMonitorApply;
import com.oceansoft.mobile.econsole.modules.jlwt.entity.SysOrg;
import com.oceansoft.mobile.econsole.modules.jlwt.persistence.ISysOrgMapper;
import com.oceansoft.mobile.econsole.modules.matters.entity.CaseInfo;
import com.oceansoft.mobile.econsole.modules.matters.persistence.ICaseMapper;
import com.oceansoft.mobile.econsole.modules.member.entity.WtMember;
import com.oceansoft.mobile.econsole.modules.member.persistence.IWtMemberMapper;
import com.oceansoft.mobile.econsole.modules.watchlog.persistence.IWatchLogMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by wzy on 2016/2/2.
 */
@Service
public class ProjectYyServiceImpl implements IProjectYyService {



    @Resource
    IProjectYyMapper projectYyMapper;
    @Resource
    ICaseMapper caseMapper;
    @Resource
    IWtMemberMapper wtMemberMapper;
    @Resource
    IWatchLogMapper watchLogMapper;
    @Resource
    ISysOrgMapper sysOrgMapper;

    private  Date ddt;

    @Override
    public List<String> getYyDataArrange(String yyq)
    {
        return  projectYyMapper.getYyDataArrange(yyq);
    }
    @Override
    public Date GetDueDate(Date StartDate, Date EndDate) {
        ddt = EndDate;
        //如果大于0,则说明日期区间存在休息日,需要把承诺时间往后推移
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(EndDate);

        Calendar calendar2=Calendar.getInstance();
        calendar2.setTime(EndDate);

        int offDaycount = 0;


        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String str = sdf.format(StartDate);
        String strEnd = sdf.format(EndDate);

        offDaycount = projectYyMapper.getOffCount(str, strEnd);
        if (offDaycount > 0)
        {
            calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)+1);
            calendar2.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)+offDaycount);
            Date dt1 =calendar.getTime();
            Date dt2 = calendar2.getTime();
            //判断往后推移的几天中存不存在休息日,如果存在则要继续往后推移
            GetDueDate(dt1, dt2);
        }
        return ddt; //承诺时间
    }

    public String CreateOrderNO(String DeptCode, String JzCode, String pt)
    {
        if(pt.isEmpty())
            pt="11";
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");

        String Ys =  sdf.format(new Date()); //年月日
        String Deptcode = DeptCode.substring(2, 8);        //省市县


        //订单前缀
        if (JzCode.length() == 1)
            JzCode = "0"+JzCode;
        //String PreNO = Ys + Deptcode + pt + JzCode;
        String PreNO =  pt + Deptcode + Ys + JzCode;


        //校验码暂时不需要
        String CheckNo = ""; // CreateCheckCode(Ys, Deptcode, pt, JzCode);

        String OrderNO = CreateMaxtOrderNO(PreNO, CheckNo);

        return OrderNO;
    }
    public String CreateMaxtOrderNO(String PreNO, String CheckCode)
    {

            try
            {


                String SequeceNum =String.valueOf(projectYyMapper.getSeqNumber(PreNO));

                SequeceNum =String.format("%04d",  Integer.parseInt(SequeceNum));
                String orderNo = PreNO + SequeceNum + CheckCode;
                projectYyMapper.inserSeqNumber(orderNo,PreNO);

                return orderNo;
            }
            catch(Exception ex)
            {

                return "";
            }

    }




    @Override
    public YyProjectEntity getYyPrjInfo(String prjGuid) {
      return    projectYyMapper.getYyInfo(prjGuid);
    }

    @Override
    public List<ArrangementInfo> getArrangeMenet(String orgId, String caseGuid, String startTime, String endTime) {
        return projectYyMapper.getArrangeMenet(orgId,caseGuid,startTime,endTime);
    }

    @Override
    public Pager getPrjYylist(Query query) {
        PageHelper.startPage(query.getPageNum(), query.getNumPerPage(), true);
        Page<ProjectInfo> page = (Page<ProjectInfo>) projectYyMapper.getPrjYyList(query);
        return PageUtil.page2pager(page, query);
    }

    @Override
    @Transactional
    public Result doArrangeJg(String caseNo, String userGuid, String orgId, String tableName,
                              String appType, HashMap<String,Object> data, String ip,String pt) {
        try {

            String apptype="";
            if(pt.equals("A"))
                apptype="4";
            if(pt.equals("W"))
                apptype="5";
            if(pt.equals("I"))
                apptype="6";

            //SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");

            CaseInfo caseInfo = caseMapper.getCaseInfo(caseNo, orgId);
            WtMember wtMember = wtMemberMapper.getWtMemberByUserGuid(userGuid);

            ProjectEntity proModel = new ProjectEntity();
            String prjBillGuid =CreateOrderNO(orgId,caseInfo.getCasePoliceCategory(),pt);
            proModel.setGuid(UUID.randomUUID().toString());
            proModel.setProjectCaseGuid(caseInfo.getGuid());
            proModel.setProjectNetBillId("");
            proModel.setProjectBillId(prjBillGuid);
            proModel.setProjectType(caseInfo.getCaseType());
            proModel.setIsPrePrj("1");
            proModel.setIsUnite("0");
            proModel.setIsCharegePrj(caseInfo.getIsPay());
            proModel.setStartDoDate(new Date());
            proModel.setDueDays(Integer.parseInt(caseInfo.getPromiseDays()));
            proModel.setUnitAttribute(wtMember.getUserType());
            proModel.setUnitName(wtMember.getAliasName());
            proModel.setUnitNumber(DesAPPUtils.decrypt(wtMember.getUserCode()));
            proModel.setUnitAddress(wtMember.getAddress());
            proModel.setTelePhone(wtMember.getUserName());
            proModel.setUnitContactor(wtMember.getLinkName());
            proModel.setHandPhone(DesAPPUtils.decrypt(wtMember.getMobile()));
            proModel.setIsDeleted("0");
            proModel.setNetProjectType(appType);
            proModel.setNetProjectCreatorGuid(userGuid);
            proModel.setCreatorGuid(userGuid);
            proModel.setCreatorDate(new Date());
            proModel.setUpDateGuid(userGuid);
            proModel.setUpDateDate(new Date());
            proModel.setFlowSetGuid(caseInfo.getFlowCode());              //工作流编号，事项获取
            proModel.setIsMydPj("0");
            proModel.setIsMailMertal(caseInfo.getIsEms());
            proModel.setProjectStatus("1");
            proModel.setProjectStatus_cn("已提交");
            proModel.setCaseNo(caseNo);
            proModel.setIsCancelPrj("0");
            proModel.setCaseJzCode(caseInfo.getCasePoliceCategory());
            proModel.setTemp8("1");
            proModel.setTemp6(tableName);

            Calendar calendar=Calendar.getInstance();
            calendar.setTime(proModel.getCreatorDate());

            int duedays = proModel.getDueDays();
            Date st = proModel.getCreatorDate();
            calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)+duedays);
            Date endtime =calendar.getTime();
            proModel.setDueDate(GetDueDate(st, endtime)); // DateTime.Parse("1900/1/1");//初始时间


            ProjectStatusEntity proStatusModel = new ProjectStatusEntity();
            proStatusModel.setGuid(proModel.getGuid());
            proStatusModel.setProjectStatus("1");
            proStatusModel.setProjectStatus_cn("已提交");
            proStatusModel.setPrjWorkFlowStatus("1");
            proStatusModel.setDueDate(proModel.getDueDate());

            IstPascMonitorApply  monitorApply = new IstPascMonitorApply();
            monitorApply.setDocNo(prjBillGuid);
            monitorApply.setDocType(caseInfo.getCaseType());
            monitorApply.setDataSouceType("21");


            monitorApply.setAppType(apptype);
            monitorApply.setDocStatus("1");
            monitorApply.setDocStatusChageTime(proStatusModel.getDueDate  ());
            monitorApply.setIsCancelPrj("0");
            monitorApply.setCancelPrjDate(proStatusModel.getDueDate());
            monitorApply.setPoliceCategory(caseInfo.getCasePoliceCategory());
            monitorApply.setCaseId(caseInfo.getRefGuid());
            monitorApply.setTemp2(caseInfo.getGuid());
            monitorApply.setCaseName(caseInfo.getCaseName());
            monitorApply.setAreaId("0");
            monitorApply.setAppDeptCode(orgId);
            monitorApply.setAppDeptName(caseInfo.getOrgName());
            monitorApply.setAppTime(new Date());
            monitorApply.setAppUserType(proModel.getUnitAttribute());
            monitorApply.setAppUserId(userGuid);
            monitorApply.setAppUserName(proModel.getUnitName());
            monitorApply.setUserCode(proModel.getUnitNumber());
            monitorApply.setAppUserAddr(proModel.getUnitAddress());
            monitorApply.setHandPhone(proModel.getHandPhone());
            monitorApply.setAppIpAddr(ip);
            monitorApply.setCreateTime(new Date());


            HashMap<String,Object> map = new HashMap<String,Object>();
            map.put("tablName",tableName);
            data.put("guid",UUID.randomUUID().toString());
            data.put("PRJGUID",proModel.getGuid());
            data.put("MATERIALGUID","");
            data.put("DOCSTATUE","");

            int persionNum = 0;
            if("Form_data_rakep".equals(tableName)||"Form_data_fpqaq".equals(tableName)||"Form_data_7jxem".equals(tableName)){
                if(!"".equals(data.get("persionXh")) && data.get("persionXh")!=null){
                    String[] per = ((String)data.get("persionXh")).split(",");
                    persionNum = (per.length+1) * 3 + 1;
                }else{
                    persionNum = 4;
                }
            }

            // 减去人数 × 3 及 persionXh
            String[] keys = new String[data.size()-persionNum];

            Set<String> sset = data.keySet();
            int i = 0;
            for (String os : sset) {
                if("Form_data_rakep".equals(tableName)||"Form_data_fpqaq".equals(tableName)||"Form_data_7jxem".equals(tableName)){
                    if(!"".equals(data.get("persionXh")) && data.get("persionXh")!=null){
                        String[] persionXh = ((String)data.get("persionXh")).split(",");
                        int flag = 0;
                        for(String xh:persionXh){
                            if("persionXh".equals(os)||("J_zyxm"+xh).equals(os)||
                                    ("G_zyname"+xh).equals(os)||("G_zyxb"+xh).equals(os)||("G_zysfzh"+xh).equals(os)||
                                    ("F_zycsny"+xh).equals(os)||("F_zyxb"+xh).equals(os)||("F_zysfzh"+xh).equals(os)||
                                    ("J_zyname"+xh).equals(os)||("J_zyxb"+xh).equals(os)||("J_zysfzh"+xh).equals(os)){
                                flag = 1;
                                break;
                            }
                        }
                        if(flag == 1){
                            continue;
                        }
                    }
                    if("persionXh".equals(os)||("J_zyxm").equals(os)||
                            ("G_zyname").equals(os)||("G_zyxb").equals(os)||("G_zysfzh").equals(os)||
                            ("F_zycsny").equals(os)||("F_zyxb").equals(os)||("F_zysfzh").equals(os)||
                            ("J_zyname").equals(os)||("J_zyxb").equals(os)||("J_zysfzh").equals(os)){
                        continue;
                    }
                }

                keys[i++] = os;
            }

            map.put("keys",keys);
            ArrayList<InCustodyPersonEntity> list = new ArrayList<InCustodyPersonEntity>();
            if("Form_data_rakep".equals(tableName)||"Form_data_fpqaq".equals(tableName)||"Form_data_7jxem".equals(tableName)){

                if(!"".equals(data.get("persionXh"))){
                    String[] persionXh = ((String)data.get("persionXh")).split(",");
                    for(String xh:persionXh){
                        InCustodyPersonEntity inCustodyPersonEntity = new InCustodyPersonEntity();
                        inCustodyPersonEntity.setGuid(UUID.randomUUID().toString());
                        inCustodyPersonEntity.setFormguid((String)data.get("guid"));
                        inCustodyPersonEntity.setFormname((String)map.get("tablName"));
                    /*if("Form_data_n0p79".equals(inCustodyPersonEntity.getFormname())){
                        inCustodyPersonEntity.setZykss((String)data.get("L_zykcs"));
                        inCustodyPersonEntity.setZyname((String)data.get("L_zyname"+xh));
                        inCustodyPersonEntity.setZyxb((String)data.get("L_zyxbb"+xh));
                        inCustodyPersonEntity.setZysfzh((String)data.get("L_zysfzhm"+xh));
                        data.remove("L_zyname"+xh);
                        data.remove("L_zyxbb"+xh);
                        data.remove("L_zysfzhm"+xh);
                    }else if("Form_data_u2e62".equals(inCustodyPersonEntity.getFormname())){
                        inCustodyPersonEntity.setZykss((String)data.get("J_zykss"));
                        inCustodyPersonEntity.setZyname((String)data.get("J_zyxm"+xh));
                        inCustodyPersonEntity.setZyxb((String)data.get("J_zyxb"+xh));
                        inCustodyPersonEntity.setZysfzh((String)data.get("J_zysfzh"+xh));
                        data.remove("J_zyxm"+xh);
                        data.remove("J_zyxb"+xh);
                        data.remove("J_zysfzh"+xh);
                    }else */
                        if("Form_data_rakep".equals(inCustodyPersonEntity.getFormname())){
                            inCustodyPersonEntity.setZykss((String)data.get("J_zykss"));
                            inCustodyPersonEntity.setZyname((String)data.get("J_zyname"+xh));
                            inCustodyPersonEntity.setZyxb((String)data.get("J_zyxb"+xh));
                            inCustodyPersonEntity.setZysfzh((String)data.get("J_zysfzh"+xh));
                            data.remove("J_zyxm"+xh);
                            data.remove("J_zyxb"+xh);
                            data.remove("J_zysfzh"+xh);
                        }else if("Form_data_fpqaq".equals(inCustodyPersonEntity.getFormname())){
                            inCustodyPersonEntity.setZykss((String)data.get("F_zykss"));
                            inCustodyPersonEntity.setZyname((String)data.get("F_zycsny"+xh));
                            inCustodyPersonEntity.setZyxb((String)data.get("F_zyxb"+xh));
                            inCustodyPersonEntity.setZysfzh((String)data.get("F_zysfzh"+xh));
                            data.remove("F_zycsny"+xh);
                            data.remove("F_zyxb"+xh);
                            data.remove("F_zysfzh"+xh);
                        }else if("Form_data_7jxem".equals(inCustodyPersonEntity.getFormname())){
                            inCustodyPersonEntity.setZykss((String)data.get("G_zykss"));
                            inCustodyPersonEntity.setZyname((String)data.get("G_zyname"+xh));
                            inCustodyPersonEntity.setZyxb((String)data.get("G_zyxb"+xh));
                            inCustodyPersonEntity.setZysfzh((String)data.get("G_zysfzh"+xh));
                            data.remove("G_zyname"+xh);
                            data.remove("G_zyxb"+xh);
                            data.remove("G_zysfzh"+xh);
                        }

                        list.add(inCustodyPersonEntity);

                    }
                }
                data.remove("persionXh");
                InCustodyPersonEntity inCustodyPerson = new InCustodyPersonEntity();
                inCustodyPerson.setGuid(UUID.randomUUID().toString());
                inCustodyPerson.setFormguid((String)data.get("guid"));
                inCustodyPerson.setFormname((String)map.get("tablName"));
                // 律师会见
           /* if("Form_data_n0p79".equals(inCustodyPerson.getFormname())){
                inCustodyPerson.setZykss((String)data.get("L_zykcs"));
                inCustodyPerson.setZyname((String)data.get("L_zyname"));
                inCustodyPerson.setZyxb((String)data.get("L_zyxbb"));
                inCustodyPerson.setZysfzh((String)data.get("L_zysfzhm"));
                data.remove("L_zyname");
                data.remove("L_zyxbb");
                data.remove("L_zysfzhm");
            }else if("Form_data_u2e62".equals(inCustodyPerson.getFormname())){//家属视频
                inCustodyPerson.setZykss((String)data.get("J_zykss"));
                inCustodyPerson.setZyname((String)data.get("J_zyxm"));
                inCustodyPerson.setZyxb((String)data.get("J_zyxb"));
                inCustodyPerson.setZysfzh((String)data.get("J_zysfzh"));
                data.remove("J_zyxm");
                data.remove("J_zyxb");
                data.remove("J_zysfzh");
            }else */
                if("Form_data_rakep".equals(inCustodyPerson.getFormname())){// 检察院提讯
                    inCustodyPerson.setZykss((String)data.get("J_zykss"));
                    inCustodyPerson.setZyname((String)data.get("J_zyname"));
                    inCustodyPerson.setZyxb((String)data.get("J_zyxb"));
                    inCustodyPerson.setZysfzh((String)data.get("J_zysfzh"));
                    data.remove("J_zyxm");
                    data.remove("J_zyxb");
                    data.remove("J_zysfzh");
                }else if("Form_data_fpqaq".equals(inCustodyPerson.getFormname())){// 法院提讯
                    inCustodyPerson.setZykss((String)data.get("F_zykss"));
                    inCustodyPerson.setZyname((String)data.get("F_zycsny"));
                    inCustodyPerson.setZyxb((String)data.get("F_zyxb"));
                    inCustodyPerson.setZysfzh((String)data.get("F_zysfzh"));
                    data.remove("F_zycsny");
                    data.remove("F_zyxb");
                    data.remove("F_zysfzh");
                }else if("Form_data_7jxem".equals(inCustodyPerson.getFormname())){// 公安提讯
                    inCustodyPerson.setZykss((String)data.get("G_zykss"));
                    inCustodyPerson.setZyname((String)data.get("G_zyname"));
                    inCustodyPerson.setZyxb((String)data.get("G_zyxb"));
                    inCustodyPerson.setZysfzh((String)data.get("G_zysfzh"));
                    data.remove("G_zyname");
                    data.remove("G_zyxb");
                    data.remove("G_zysfzh");
                }
                list.add(inCustodyPerson);
            }


            map.put("params", data);

            // L_zyname L_zyxbb L_zysfzhm  persionXh
            projectYyMapper.insertProject(proModel); //办件表
            //projectYyMapper.insertProjectStatus(proStatusModel);//办件状态表
            projectYyMapper.formInsert(map);
            // 在押人员表插入数据
            for(InCustodyPersonEntity custodyPerson : list){
                projectYyMapper.insertInCustody(custodyPerson);
            }
            projectYyMapper.insertMonitApply(monitorApply);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            return new Result(Result.FAILURE,"预约失败!");
        }
        return new Result(Result.SUCC,"预约成功!");
    }

    @Override
    @Transactional
    public Result doArrange(String caseNo, String userGuid, String orgId, String yyTime,String yySpan,String addr,String ip,String pt) {

        String prjGuid = "";
        try {
            String apptype="";
            if(pt.equals("A"))
                apptype="4";
            if(pt.equals("W"))
                apptype="5";
            if(pt.equals("I"))
                apptype="6";
            SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
            String perfix = "BJ" + sf.format(new Date());


            SysOrg org = sysOrgMapper.findByGuid(orgId);
            String yyPerfix = sf.format(new Date());
            int yyMax = projectYyMapper.getYyNo(yyPerfix);
            String prjYYNo = "YY"+yyPerfix + String.format("%03d", yyMax);


            CaseInfo caseInfo = caseMapper.getCaseInfo(caseNo, orgId);
            WtMember wtMember = wtMemberMapper.getWtMemberByUserGuid(userGuid);

            ProjectEntity proModel = new ProjectEntity();

            //String prjBillGuid =CreateOrderNO(orgId,caseNo,"11");
            String prjBillGuid =CreateOrderNO(orgId,caseInfo.getCasePoliceCategory(),pt);
            proModel.setGuid(UUID.randomUUID().toString());
            prjGuid = proModel.getGuid();
            proModel.setProjectCaseGuid(caseInfo.getGuid());
            //proModel.setProjectCaseGuid(caseInfo.getGuid());
            proModel.setProjectNetBillId("");
            proModel.setProjectBillId(prjBillGuid);
            proModel.setProjectType(caseInfo.getCaseType());
            //proModel.setProjectType("1");
            proModel.setIsPrePrj("1");
            proModel.setIsUnite("0");
            proModel.setIsCharegePrj(caseInfo.getIsPay());
            //proModel.setIsCharegePrj("0");
            proModel.setStartDoDate(new Date());
            proModel.setDueDays(Integer.parseInt(caseInfo.getPromiseDays()));
            //proModel.setDueDays(Integer.parseInt("1"));
            proModel.setUnitAttribute(wtMember.getUserType());

            proModel.setUnitName(wtMember.getAliasName());

            proModel.setUnitNumber(DesAPPUtils.decrypt(wtMember.getUserCode()));

            proModel.setUnitAddress(wtMember.getAddress());
            proModel.setTelePhone(wtMember.getUserName());
            proModel.setUnitContactor(wtMember.getLinkName());
            proModel.setHandPhone(DesAPPUtils.decrypt(wtMember.getMobile()));
            proModel.setIsDeleted("0");
            proModel.setNetProjectType(apptype);
            proModel.setNetProjectCreatorGuid(userGuid);
            proModel.setCreatorGuid(userGuid);
            proModel.setCreatorDate(new Date());
            proModel.setUpDateGuid(userGuid);
            proModel.setUpDateDate(new Date());
            proModel.setFlowSetGuid(caseInfo.getFlowCode());              //工作流编号，事项获取
           // proModel.setFlowSetGuid(caseInfo.getFlowCode());
            proModel.setIsMydPj("0");
            proModel.setIsMailMertal(caseInfo.getIsEms());
            //proModel.setIsMailMertal("0");
            proModel.setProjectStatus("1");
            proModel.setProjectStatus_cn("已提交");
            proModel.setCaseNo(caseNo);
            proModel.setIsCancelPrj("0");
            proModel.setCaseJzCode(caseInfo.getCasePoliceCategory());
            //proModel.setCaseJzCode(caseNo);
            proModel.setTemp8("1");


            Calendar calendar=Calendar.getInstance();
            calendar.setTime(proModel.getCreatorDate());

            int duedays = proModel.getDueDays();
            Date st = proModel.getCreatorDate();
            calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)+duedays);
            Date endtime =calendar.getTime();
            proModel.setDueDate(GetDueDate(st, endtime)); // DateTime.Parse("1900/1/1");//初始时间


            ProjectStatusEntity proStatusModel = new ProjectStatusEntity();
            proStatusModel.setGuid(proModel.getGuid());
            proStatusModel.setProjectStatus("1");
            proStatusModel.setProjectStatus_cn("已提交");
            proStatusModel.setPrjWorkFlowStatus("1");
            proStatusModel.setDueDate(proModel.getDueDate());



            YyProjectEntity yyObj = new YyProjectEntity();
            yyObj.setGuid(UUID.randomUUID().toString());
            yyObj.setYysType("1");

            yyObj.setPrjGuid(proModel.getGuid());
            yyObj.setYyNo(prjYYNo);



            yyObj.setTimeSpan(yySpan);
            try {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                Date dt = sdf.parse(yyTime);
                yyObj.setYyDate(dt);

            } catch (Exception e) {
                e.printStackTrace();
            }
            IstPascMonitorApply  monitorApply = new IstPascMonitorApply();

            monitorApply.setDocNo(prjBillGuid);


            monitorApply.setDocType(caseInfo.getCaseType());
            //monitorApply.setDocType("1");
            monitorApply.setDataSouceType("21");


            monitorApply.setAppType(apptype);

            monitorApply.setDocStatus("1");

            monitorApply.setDocStatusChageTime(proStatusModel.getDueDate());



            monitorApply.setIsCancelPrj("0");

            monitorApply.setCancelPrjDate(proStatusModel.getDueDate());

            monitorApply.setPoliceCategory(caseInfo.getCasePoliceCategory());
           // monitorApply.setPoliceCategory(caseNo);
            monitorApply.setCaseId(caseInfo.getRefGuid());
            monitorApply.setTemp2(caseInfo.getGuid());
           // monitorApply.setCaseId(caseInfo.getGuid());
            monitorApply.setCaseName(caseInfo.getCaseName());
            //monitorApply.setCaseName(caseInfo.getCaseName());
            monitorApply.setAreaId("0");

            monitorApply.setAppDeptCode(orgId);

           monitorApply.setAppDeptName(caseInfo.getOrgName());
           // monitorApply.setAppDeptName(org.getOrgName());
            monitorApply.setAppTime(new Date());

            monitorApply.setAppUserType(proModel.getUnitAttribute());

            monitorApply.setAppUserId(userGuid);

            monitorApply.setAppUserName(proModel.getUnitName());

            monitorApply.setUserCode(proModel.getUnitNumber());

            monitorApply.setAppUserAddr(proModel.getUnitAddress());

            monitorApply.setHandPhone(proModel.getHandPhone());

            monitorApply.setAppIpAddr(ip);
            monitorApply.setCreateTime(new Date());




            projectYyMapper.insertProject(proModel); //办件表
           // projectYyMapper.insertProjectStatus(proStatusModel);//办件状态表
            projectYyMapper.insertYyProject(yyObj); //预约表
            projectYyMapper.insertMonitApply(monitorApply);
            //projectYyMapper.insertYyProjectStatus(yyS);//预约状态表
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            return new Result(Result.FAILURE,"预约失败!");
        }
        return new Result(Result.SUCC,prjGuid,"预约成功!");
    }

    @Override
    public int insertProjectMaterial(ProjectMaterialEntity projectMaterialEntity){
        // 办件材料表插入记录
        return projectYyMapper.insertProjectMaterial(projectMaterialEntity);
    }
}
